<template>
  <el-container class="main_container">
    <el-header>
<!--logo和项目名-->
      <div class="left_box">
        <img src="../../public/img/logo.jpg">
        <span>嵌入式班级管理系统</span>
      </div>
<!--右侧姓名和头像-->
      <div class="right_box">
        <span style="font-size: small">{{ userName }}({{ roleName }})</span>
        <el-dropdown>
        <span class="el-dropdown-link">
          <el-avatar :size="30" :src="circleUrl" style="margin: 0px 10px 0px 15px"></el-avatar>
        </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-house">系统首页</el-dropdown-item>
            <el-dropdown-item icon="el-icon-ship">讨论交流</el-dropdown-item>
            <el-dropdown-item icon="el-icon-switch-button">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'64px':'200px'">
        <div class="toggle_box" @click="toggleCollapse">|||</div>
<!--侧边栏-->
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#333333"
          text-color="#fff"
          active-text-color="cornflowerblue"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="$route.path">
          <MenuTree :menuList="this.MenuList"></MenuTree>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import MenuTree from '@/components/MenuTree'
import {postRequest} from "../utils/api";
export default {
  name: 'Main',
  data(){
    return {
      circleUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
      isCollapse: false,
      MenuList: [
          {
              "menu_id": '' ,
              "menu_name": '',
              "icon": '',
              "path": '',
              "children": ''
          }
      ],
      userName: '',
      roleName: ''
    }
  },
  components: {
    MenuTree
  },
    created() {
        postRequest('/menu/all').then(resp=>{
            if (resp) {
                console.log(JSON.stringify(resp))
                this.MenuList=resp

            }
        })
      postRequest('/user/userMessage').then(resp=>{
        if (resp){
          console.log(JSON.stringify(resp))
          this.userName = resp.name;
          this.roleName = resp.roleName;
        }
      })
    },
    methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    toggleCollapse(){
      this.isCollapse = !this.isCollapse;
    }
  }
}
</script>

<style scoped>
.main_container{
  height: 750px;
}
.el-header  {
  background-color: #333333;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  color: #FFFFFF;
  align-items: center;
  font-size: 20px;
}
.left_box{
  display: flex;
  align-items: center;
}
.left_box img{
  width: 50px;
  height: 50px;
  border-radius: 25px;
  margin: 0px 10px 5px 15px ;
}
.right_box{
  display: flex;
  align-items: center;
}
.el-aside {
  background-color: #333333;
  color: #333;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

/*折叠展开收起*/
.el-aside .toggle_box{
  background-color: cornflowerblue;
  font-size: 15px;
  font-weight: bold;
  line-height: 25px;
  color: #FFFFFF;
  letter-spacing: 0.2em;
  text-align: center;
  cursor: pointer;
}
.el-aside .el-menu{
  border-right: none;
}
</style>
